﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestConsoleApp
{
    public class TestEventAndDelegate
    {
        private delegate void MyHandler();

        private static event MyHandler MyEvent;

        public static void Test()
        {
            //MyHandler myHandler = (arg) =>
            //{
            //    Console.WriteLine(arg);
            //};


            #region 委托
            MyHandler myHandler = () => { Console.WriteLine("1"); };
            #endregion           
            #region 委托链
            myHandler += () => { Console.WriteLine("2"); };
            myHandler += () => { Console.WriteLine("3"); };
            myHandler += () => { Console.WriteLine("4"); };

            myHandler();
            #endregion


            #region 事件
            MyEvent += TestEventAndDelegate_MyEvent;

            MyEvent(); 
            #endregion
        }

        private static void TestEventAndDelegate_MyEvent()
        {
            Console.WriteLine("5");
        }
    }
}
